const Router = require('koa-router')

const { register, login, changePassword } = require('../controller/users.controller')

// 验证数据合法性中间件
const { userValidator, userVerify, loginVerify, cryptPassword } = require('../middleware/users.middleware')
// token认证中间件
const { auth } = require('../middleware/auth.middleware')
// 创建实例 , 并设置基地址
const router = new Router({ prefix: '/users' })

// 注册接口
router.post('/register', userValidator, userVerify, cryptPassword, register)

// 登录接口
router.post('/login', userValidator, loginVerify, login)

// 修改密码接口
// patch与put的区别 , put更趋向于修改全部数据
router.patch('/', auth, cryptPassword, changePassword)
module.exports = router